function Settings() {
    this.soundStatus = 'on'; // on or off
    this.screenSize = 'regular'; // regular or fullscreen
    this.details = 'high'; // high or low

    sound = getItemFromLocalstorage('soundStatus');
    if (sound !== null) {
        if (sound != this.soundStatus) {
            this.toggleSound();
        }
    }

    detail = getItemFromLocalstorage('details');
    if (detail !== null) {
        if (detail != this.details) {
            this.toggleDetails();
        }
    }
}
Settings.method('isSoundOn', function () {
    return this.soundStatus == 'on';
});
Settings.method('isFullscreen', function () {
    return this.screenSize == 'fullscreen';
});
Settings.method('isHighDetail', function () {
    return this.details == 'high';
});

Settings.method('toggleSound', function () {
    if (this.soundStatus == 'on') {
        this.soundStatus = 'off';
        $('#settings #volume').css('background-position', '-173px -230px');
        $('#settings #volume').mouseover(function() {
            $(this).css('background-position', '-173px -262px');
        });
        $('#settings #volume').mouseout(function() {
            $(this).css('background-position', '-173px -230px');
        });
        // turn playing sounds off when mute is pressed
        for (var i = 0; i < OurGame.bombs.length; i ++) {
            if (OurGame.bombs[i] != undefined) {
                if (OurGame.bombs[i].explosionSoundInstance instanceof Audio) {
                    OurGame.bombs[i].explosionSoundInstance.pause();
                }
                if (OurGame.bombs[i].expansionSoundInstance instanceof Audio) {
                    OurGame.bombs[i].expansionSoundInstance.pause();
                }
            }
        }
    }
    else {
        this.soundStatus = 'on';
        $('#settings #volume').css('background-position', '-205px -230px');
        $('#settings #volume').mouseover(function() {
            $(this).css('background-position', '-205px -262px');
        });
        $('#settings #volume').mouseout(function() {
            $(this).css('background-position', '-205px -230px');
        });
    }
    setItemToLocalStorage('soundStatus', this.soundStatus);
});

function markFullScreenSelected() {
    $('#settings #screen-size').css('background-position', '-270px -230px');
    $('#settings #screen-size').mouseover(function () {
        $(this).css('background-position', '-270px -262px');
    });
    $('#settings #screen-size').mouseout(function () {
        $(this).css('background-position', '-270px -230px');
    });
}

function markFullScreenNOTSelected() {
    $('#settings #screen-size').css('background-position', '-238px -230px');
    $('#settings #screen-size').mouseover(function () {
        $(this).css('background-position', '-238px -262px');
    });
    $('#settings #screen-size').mouseout(function () {
        $(this).css('background-position', '-238px -230px');
    });
}

Settings.method('toggleScreenSize', function () {
    if (this.screenSize == 'regular') {
        log("this.screenSize == 'regular'");
        this.screenSize = 'fullscreen';
        log(document.getElementsByTagName("html")[0]);
        window.fullScreenApi.requestFullScreen(document.getElementsByTagName("html")[0]);
        markFullScreenSelected();
    } else {
        log("this.screenSize == 'fullscreen'");
        this.screenSize = 'regular';
        window.fullScreenApi.cancelFullScreen(document.getElementsByTagName("html")[0]);
        markFullScreenNOTSelected();
    }
    setItemToLocalStorage('screenSize', this.screenSize);
});

Settings.method('toggleDetails', function () {
    if (this.details == 'high') {
        this.details = 'low';
        $('#settings #details').css('background-position', '-300px -230px');
        $('#settings #details').mouseover(function() {
            $(this).css('background-position', '-300px -262px');
        });
        $('#settings #details').mouseout(function() {
            $(this).css('background-position', '-300px -230px');
        });
    } else {
        this.details = 'high';
        $('#settings #details').css('background-position', '-330px -230px');
        $('#settings #details').mouseover(function() {
            $(this).css('background-position', '-330px -260px');
        });
        $('#settings #details').mouseout(function() {
            $(this).css('background-position', '-330px -230px');
        });
    }
    setItemToLocalStorage('details', this.details);
});


$('#settings #volume').click(function() {
    OurGame.settings.toggleSound();
});
$('#settings #screen-size').click(function() {
    OurGame.settings.toggleScreenSize();
});
$('#settings #details').click(function() {
    OurGame.settings.toggleDetails();
});